//
//  MBHomeListHeaderView.m
//  Meboo
//
//  Created by kyo on 2024/4/26.
//

#import "MBHomeListHeaderView.h"

@interface MBHomeListHeaderView ()
@property (nonatomic, strong) UIButton *pictureBtn;
@property (nonatomic, strong) UIButton *videoBtn;

@property (nonatomic, strong) UIView *pictureView;
@property (nonatomic, strong) UIView *videoView;
@end

@implementation MBHomeListHeaderView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}


#pragma mark - Action
- (void)pictureAction {
    [self.pictureBtn setTitleColor:HEXS(@"B92176") forState:0];
    self.pictureBtn.titleLabel.font = PDSemiBoldScale(20);
    self.pictureView.hidden = NO;
    
    [self.videoBtn setTitleColor:HEXS(@"666666") forState:0];
    self.videoBtn.titleLabel.font = PDRegularScale(20);
    self.videoView.hidden = YES;
    
    if (self.switchBlock) {
        self.switchBlock(NO);
    }
}

- (void)videoAction {
    [self.videoBtn setTitleColor:HEXS(@"B92176") forState:0];
    self.videoBtn.titleLabel.font = PDSemiBoldScale(20);
    self.videoView.hidden = NO;
    
    [self.pictureBtn setTitleColor:HEXS(@"666666") forState:0];
    self.pictureBtn.titleLabel.font = PDRegularScale(20);
    self.pictureView.hidden = YES;
    
    if (self.switchBlock) {
        self.switchBlock(YES);
    }
}

#pragma mark - UI
- (void)setupUI {
    
    self.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.pictureBtn];
    [self.pictureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(18));
        make.centerY.equalTo(self);
    }];
    
    [self addSubview:self.pictureView];
    [self.pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(MBWidthScale(18));
        make.height.mas_equalTo(MBWidthScale(3));
        make.bottom.equalTo(self);
        make.centerX.equalTo(self.pictureBtn);
    }];
    
    [self addSubview:self.videoBtn];
    [self.videoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.pictureBtn.mas_right).offset(MBWidthScale(30));
        make.centerY.equalTo(self);
    }];
    
    [self addSubview:self.videoView];
    [self.videoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(MBWidthScale(18));
        make.height.mas_equalTo(MBWidthScale(3));
        make.bottom.equalTo(self);
        make.centerX.equalTo(self.videoBtn);
    }];
}

#pragma mark - Setter && Getter

- (UIButton *)videoBtn {
    if (!_videoBtn) {
        _videoBtn = [UIButton new];
        [_videoBtn setTitle:@"VIDEOS" forState:0];
        [_videoBtn setTitleColor:HEXS(@"666666") forState:0];
        _videoBtn.titleLabel.font = PDRegularScale(20);
        [_videoBtn addTarget:self action:@selector(videoAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _videoBtn;
}

- (UIButton *)pictureBtn {
    if (!_pictureBtn) {
        _pictureBtn = [UIButton new];
        [_pictureBtn setTitle:@"PICTURES" forState:0];
        [_pictureBtn setTitleColor:HEXS(@"B92176") forState:0];
        _pictureBtn.titleLabel.font = PDSemiBoldScale(20);
        [_pictureBtn addTarget:self action:@selector(pictureAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _pictureBtn;
}

- (UIView *)pictureView {
    if (!_pictureView) {
        _pictureView = [UIView new];
        _pictureView.backgroundColor = HEXS(@"B92176");
        _pictureView.layer.cornerRadius = MBHeightScale(1.5);
    }
    return _pictureView;
}

- (UIView *)videoView {
    if (!_videoView) {
        _videoView = [UIView new];
        _videoView.backgroundColor = HEXS(@"B92176");
        _videoView.layer.cornerRadius = MBHeightScale(1.5);
        _videoView.hidden = YES;
    }
    return _videoView;
}
@end
